home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 February / Macworld (1999-02).dmg / Cinema 4D GO demo / Gumption Plug-ins / Plug-ins / Freeware / ResolveLoops / ResolveLoops.cof
Text File  |  1998-03-19  |  2KB  |  107 lines

  1. // ResolveLoops
  2. // resolve a looped sequence in a sequence without loops
  3. // You can select a sequence, track or an entire object
  4. // Christian Losch
  5. // (c) 1998 MAXON Computer
  6.  
  7. DoSequence(seq,fps)
  8. {
  9.     var count,arr,i,j,key,si,loops,diff;
  10.  
  11.     si = new(SequenceInfo);
  12.  
  13.     seq->GetSequenceInfo(si);
  14.  
  15.     diff = si->to - si->from + 1.0/fps;
  16.     si->to = diff*(si->loops+1) - 1.0/fps;
  17.  
  18.     loops = si->loops; if (loops==0) return; // nothing to do
  19.     si->loops = 0;
  20.  
  21.     seq->SetSequenceInfo(si);
  22.  
  23.     // Countkeys
  24.     count=0;
  25.     key = seq->GetFirstKey();
  26.     while (key)
  27.     {
  28.         count++;
  29.         key = key->GetNext();
  30.     }
  31.  
  32.     arr = new(array,count);
  33.  
  34.     // Insert Data
  35.     count=0;
  36.     key = seq->GetFirstKey();
  37.     while (key)
  38.     {
  39.         arr[count] = key->GetTime();
  40.         count++;
  41.         key = key->GetNext();
  42.     }
  43.  
  44.     key = seq->GetFirstKey();
  45.     for (i=0; i<count; i++)
  46.     {
  47.         for (j=0; j<loops; j++)
  48.             seq->CloneKey(arr[i]+diff*(j+1),key);
  49.  
  50.         key = key->GetNext();
  51.     }
  52. }
  53.  
  54. DoTrack(track,fps)
  55. {
  56.     var seq = track->GetFirstSequence();
  57.     while (seq)
  58.     {
  59.         DoSequence(seq,fps);
  60.         seq = seq->GetNext();
  61.     }
  62. }
  63.  
  64. DoObject(op,fps)
  65. {
  66.     var track = op->GetFirstTrack();
  67.     while (track)
  68.     {
  69.         DoTrack(track,fps);
  70.         track = track->GetNext();
  71.     }
  72. }
  73.  
  74. Function(doc)
  75. {
  76.     var op,track,seq;
  77.  
  78.     op    = doc->FindFirstActiveAObject();
  79.     track = doc->FindFirstActiveATrack();
  80.     seq   = doc->FindFirstActiveASequence();
  81.  
  82.     if (op)
  83.     {
  84.         DoObject(op,doc->GetFps());
  85.         doc->SendMessage(ACTIVE_OBJECT_CHANGED);
  86.     }
  87.     else if (track)
  88.     {
  89.         DoTrack(track,doc->GetFps());
  90.         doc->SendMessage(ACTIVE_OBJECT_CHANGED);
  91.     }
  92.     else if (seq)
  93.     {
  94.         DoSequence(seq,doc->GetFps());
  95.         doc->SendMessage(ACTIVE_OBJECT_CHANGED);
  96.     }
  97.     else
  98.     {
  99.         TextDialog("Please select a sequence,| track or object");
  100.         return;
  101.     }
  102. }
  103.  
  104. main()
  105. {
  106.     RegisterMenuHook("Resolve Loops","Function");
  107. }